import { defineStore } from "pinia";

interface UserState {
    name: string;
    age: number;
}

export const useUserStore = defineStore("user", {
    state: (): UserState => ({
        name: "张三",
        age: 18,
    }),
    getters: {
        // 自动推导 state 类型
        doubleAge: (state) => state.age * 2,
    },
    actions: {
        setName(newName: string) {
            this.name = newName;
        },
        grow() {
            this.age++;
        },
    },
});
